﻿using System;
using System.Text;

namespace OpenFileTransfer.Util.Extensions
{
    public static class ExceptionExtension
    {
        public static string GetMessageWithInnerException(this Exception exception)
        {
            return exception.InnerException == null
                ? exception.Message
                : $"{exception.Message}{Environment.NewLine}({exception.InnerException.Message})";
        }

        public static string GetFullMessage(this Exception exception)
        {
            var sb = new StringBuilder(exception.Message);
            var innerException = exception.InnerException;
            while (innerException != null)
            {
                sb.Append(Environment.NewLine);
                sb.Append($"{innerException.Message}");
                innerException = innerException.InnerException;
            }

            return sb.ToString();
        }
    }
}
